const { $fn } = window

const child = [
	$fn.menu.preview_report, 	// 预览报告单
	{ title: '合并项目管理', path: 'merge-project-list', component:'testing-center/pages/merge-project-list', cache:true,
		children:[
			$fn.menu.preview_report 	// 预览报告单
		]
	},
	$fn.menu.preview_audit_report,		// 预览并批准报告单
	{ title: '检测项目', path: 'test-project', component:'system-settings/project-settings/test-project', cache:true,
		children:[
			{ title: '设置单一项目', 	path: 'set-single-project', component:'system-settings/project-settings/test-project/set-single-project', cache:true,
				children: [
					{ title: '项目关联', path:'project-related', component:'laboratory-manage/device/project-related'},
				]
			},
			{ title: '新增从属项目', 	path: 'new-add-project', component:'system-settings/project-settings/test-project/new-add-project', cache:true},
			{ title: '设定组合项目', 	path: 'set-group-project', component:'system-settings/project-settings/test-project/set-group-project', cache:true},
			{ title: '设置营销项目', 	path: 'set-marketing-project', component:'system-settings/project-settings/test-project/set-marketing-project', cache:true},
			$fn.menu.preview_report, // 预览报告单
		]
	}
]

const Index = function(id){
	const menu = $fn.local('menu')
	if($fn.hasArray(menu)){
		const arr = menu.filter( v => v['menu_en'] === id )
		if($fn.hasArray(arr)){
			const data = arr[0].children
			
			data.forEach( v => {
				v.children.forEach(rows => {
					const { model, project, path } = rows
					rows.path = path + '/' + model + '/' + project
					rows.child = child
					rows.cache = true
					rows.component = +model === 0 ? '404' : 'testing-center/model'
				})
			})
			let to = null
			const children = data?.[0]?.children
			
			if( $fn.hasArray(children) ){
				to = children[0].path
				to = to.replace('/','')
			}
			
			this.setState({ data, skip:{ to }  })
			
			return data 
		}else{
			$fn.toast('菜单未读取成功，请重新登录')
			$fn.push(this,'/login')
			return []
		}
	}else{
		$fn.toast('菜单未读取成功，请重新登录')
		$fn.push(this,'/login')
		return []
	}
}

export default Index